<?php
/**
 * CreateTime: 2022/8/24 13:45
 */

namespace App\Func;

use App\Models\Staff\StaffModel;
use App\Tools\DingTalk\DingTalkMsgFacade;

class DingTalkMsgFunc
{
    # send ding_talk msg by ding_talk msg type
    # msgType : text
    #          Params : text.content : "消息体"
    # msgType : oa
    #          Params : oa.head : "消息头"
    #                   oa.head.bgcolor : "消息头部的背景颜色" (FFBBBBBB)
    #                   oa.head.text : "头部标题,长度限制为最多10个字符"
    #                   oa.body : "消息体"
    #                   oa.body.title : "消息体的标题，建议50个字符以内"
    #                   oa.body.content : "消息体的内容，最多显示3行"
    #                   oa.body.image : "消息体中的图片，支持图片资源@mediaId。建议宽600像素 x 400像素，宽高比3 : 2"
    #                   oa.body.rich : "单行富文本信息"
    #                   oa.body.rich.num : "单行富文本信息的数目"
    #                   oa.body.rich.unit : "单行富文本信息的单位"
    #                   oa.body.file_count : "自定义的附件数目。此数字仅供显示，钉钉不作验。"
    #                   oa.body.author : "自定义的作者名字"
    #                   oa.message_url : "消息点击链接地址，当发送消息为小程序时支持小程序跳转链接"
    #                   oa.pc_message_url : "PC端点击消息时跳转到的地址"
    #


    public static function normalRemindMessage($userListIdArray,$message,$title){
        // 自动转换ID
        $dingTalkUsers = (new StaffModel())->getStaffInfoByStaffIds($userListIdArray,'staff_dingding_account');
        if($dingTalkUsers){
            $dingTalkUsers = implode(",",array_column($dingTalkUsers->toArray(),'staff_dingding_account'));
        }
        $data = [
            'content' => $message,
            'title' => $title
        ];

        return DingTalkMsgFacade::sendOAMessageByUserList($dingTalkUsers,$data);
    }

    /**
     * 根据用户发送消息
     * @param $userList "110469380821615386,1"
     * @param $sendMsgData
     * @return bool
     */
    public static function sendCustormDingTalkMsgByUserList($userList,$sendMsgData){
        return DingTalkMsgFacade::sendOAMessageByUserList($userList,$sendMsgData);
    }

    /**
     * 根据部门号发送消息
     * @param $deptList
     * @param $sendMsgData
     * @return bool
     */
    public static function sendCustormOAMessageByDeptList($deptList,$sendMsgData){
        return DingTalkMsgFacade::sendOAMessageByUserList($deptList,$sendMsgData);
    }
}